# _*_coding:utf-8 _*_
# @Time   :2020/6/28
import os
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler

from core.smart import SmartRobot


def heartbeat():
    """
    此函数用来向服务器发送心跳包，代表程序运行正常 1/20mins
    等待接口中
    :return:
    """
    pass


def myjob():
    """
    执行报平安服务 8-17 点每 30min 执行一次，传入最新的时间
    :return:
    """
    print('开始报平安 {}'.format(datetime.now().strftime("%H:%M")))
    myrobot = SmartRobot()
    myrobot.main(datetime.now().strftime("%H:%M"))


def tick():
    print('Tick ! time is {}'.format(datetime.now().strftime("%H:%M")))


if __name__ == '__main__':
    print('try start! {}'.format(datetime.now().strftime("%H:%M")))
    scheduler = BlockingScheduler()
    scheduler.add_job(myjob, 'cron', hour='8-23', minute='0,30')
    try:
        scheduler.start()
        print('Scheduler start! {}'.format(datetime.now().strftime("%H:%M")))
    except (KeyboardInterrupt, SystemExit):
        print('Scheduler error! {}'.format(datetime.now().strftime("%H:%M")))
        pass
